import java.util.HashSet;

/**
 * Created by losor on 2016/9/30.
 */
public class _349_Intersection_of_Two_Arrays {

    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet hashSet1 = new HashSet();
        HashSet hashSet2 = new HashSet();
        HashSet hashSet3 = new HashSet();
        for (int aNums1 : nums1) {
            hashSet1.add(aNums1);
        }
        for(int aNum2 : nums2){
            hashSet2.add(aNum2);
        }
        for (Object o: hashSet1){
            if (hashSet2.contains(o)){
                hashSet3.add(o);
            }
        }
        int[] output = new int[hashSet3.size()];
        int count = 0;
        for (Object o: hashSet3){
            output[count] = (int)o;
            count ++;
        }
        return output;
    }
}
